using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iopt.solvency.pillarone.client.desktop.Views;
using Microsoft.VisualBasic;
using System.Collections;
using System.Diagnostics;
using System.Xml.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Runtime.CompilerServices;
using iopt.solvency.pillarone.client.desktop.Helpers;

namespace iopt.solvency.pillarone.client.desktop.ViewModels
{
    public class VMParameterDesigner : VMTool
    {
        public VMParameterDesigner()
        {
            this.View = new ParameterDesigner();
            this.Caption = "Designer de parametres";
        }

        private ObservableCollection<ModelParameterDefinition> _Params = new ObservableCollection<ModelParameterDefinition>();
        public ObservableCollection<ModelParameterDefinition> Params
        {
            get { return _Params; }
            set
            {
                _Params = value;
                OnPropertyChanged("Params");
            }
        }

        public DelegateCommand AddParamCommand
        {
            get { return new DelegateCommand(AddParamExecute); }
        }
        private void AddParamExecute(object parameter)
        {
            _Params.Add(new ModelParameterDefinition
            {
                Name = "param_" + Generated(),
                UnderlyingType = ModelParamUnderLyingType.Double,
                IsSegmentable = true
            });
        }

        public DelegateCommand GenerateCodeCommand
        {
            get { return new DelegateCommand(GenerateCodeExecute); }
        }
        private void GenerateCodeExecute(object parameter)
        {
            var provider = new VBCodeProvider();
            foreach (var m in Params)
            {
                m.Code = m.GetCode(provider);
            }
        }

        private int genid = 0;
        private string Generated()
        {
            genid += 1;
            return genid.ToString();
        }
    }
}
